package com.meitianhui.convenitenbuy.widget.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.meitianhui.convenitenbuy.R;

/**
 * 是否设置为默认的门店
 * 是跟否弹窗
 */

public class SettingStoreDialog extends Dialog implements View.OnClickListener {

    private Context mContext;
    private Activity mActivity;
    /** 确定按钮 */
    private Button confirmBtn;

    /** 取消按钮 */
    private Button cancelBtn;
    private AlertDialogListener mAlertDialogListener;

    private TextView quit_dialog_content_tv, quit_dialog_content_tv2, quit_dialog_content_tv3;
    private TextView quit_dialog_title_tv;

    public SettingStoreDialog(Activity context, AlertDialogListener l) {
        this(context, R.style.dialog_custom, l);
        // super(context);
        // this.mContext = context;
        // mActivity = context;
        // this.mAlertDialogListener = l;
    }

    public SettingStoreDialog(Activity context, int themeResId, AlertDialogListener l) {
        super(context, themeResId);
        mContext = context;
        mActivity = context;
        this.mAlertDialogListener = l;
    }

    public void setDialogContent(int text) {
        quit_dialog_content_tv.setText(text);
    }

    public void setDialogContent(String text) {
        quit_dialog_content_tv.setText(text);
    }

    // 仅用于推荐人页面的行信息显示
    public void setDialogContentLine2(String text) {
        quit_dialog_content_tv2.setVisibility(View.VISIBLE);
        quit_dialog_content_tv2.setText(text);
    }

    public void setDialogContentLine3(String text) {
        quit_dialog_content_tv3.setVisibility(View.VISIBLE);
        quit_dialog_content_tv3.setText(text);
    }

    public void setDialogTitle(int text) {
        quit_dialog_title_tv.setText(text);
    }

    public void setDialogTitle(String text) {
        quit_dialog_title_tv.setText(text);
    }

    public void setConfirmBtnText(String text) {
        confirmBtn.setText(text);
    }

    public void setCancelBtnText(String text) {
        cancelBtn.setText(text);
    }

    public void showCancelBtn(boolean isShow) {
        if (isShow) {
            cancelBtn.setVisibility(View.VISIBLE);
        } else {
            cancelBtn.setVisibility(View.GONE);
        }
    }

    public void setFalseCancelable() {
        setCancelable(false);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 指定布局
        this.setContentView(R.layout.dialog_setting_store);
        DisplayMetrics metric = new DisplayMetrics();
        try {
            mActivity.getWindowManager().getDefaultDisplay().getMetrics(metric);
            WindowManager.LayoutParams p = getWindow().getAttributes();
            p.width = metric.widthPixels - 100;
            Window window = getWindow();
            window.setAttributes(p);
            window.setGravity(Gravity.CENTER);
        } catch (Exception e) {
            e.printStackTrace();
        }
        setCancelable(true);
        this.setCanceledOnTouchOutside(true);

        confirmBtn = (Button) findViewById(R.id.confirm_btn);
        cancelBtn = (Button) findViewById(R.id.cancel_btn);
        quit_dialog_title_tv = (TextView) findViewById(R.id.quit_dialog_title_tv);
        quit_dialog_content_tv = (TextView) findViewById(R.id.quit_dialog_content_tv);
        quit_dialog_content_tv2 = (TextView) findViewById(R.id.quit_dialog_content_tv2);
        quit_dialog_content_tv3 = (TextView) findViewById(R.id.quit_dialog_content_tv3);
        // 为按钮绑定点击事件监听器
        confirmBtn.setOnClickListener(this);
        cancelBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.confirm_btn:
                mAlertDialogListener.onConfirmClick();
                break;
            case R.id.cancel_btn:
                mAlertDialogListener.onCancelClick();
                break;
        }
    }

    public interface AlertDialogListener {
        void onConfirmClick();

        void onCancelClick();
    }

}
